<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>linkdialogplugin_test.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_editor_plugins_linkdialogplugin_test.js.html">linkdialogplugin_test.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2010 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>goog.provide(&#39;goog.ui.editor.LinkDialogTest&#39;);
<a name="line16"></a>goog.setTestOnly(&#39;goog.ui.editor.LinkDialogTest&#39;);
<a name="line17"></a>
<a name="line18"></a>goog.require(&#39;goog.dom&#39;);
<a name="line19"></a>goog.require(&#39;goog.dom.DomHelper&#39;);
<a name="line20"></a>goog.require(&#39;goog.dom.NodeType&#39;);
<a name="line21"></a>goog.require(&#39;goog.dom.TagName&#39;);
<a name="line22"></a>goog.require(&#39;goog.editor.BrowserFeature&#39;);
<a name="line23"></a>goog.require(&#39;goog.editor.Command&#39;);
<a name="line24"></a>goog.require(&#39;goog.editor.Field&#39;);
<a name="line25"></a>goog.require(&#39;goog.editor.Link&#39;);
<a name="line26"></a>goog.require(&#39;goog.editor.plugins.LinkDialogPlugin&#39;);
<a name="line27"></a>goog.require(&#39;goog.string&#39;);
<a name="line28"></a>goog.require(&#39;goog.string.Unicode&#39;);
<a name="line29"></a>goog.require(&#39;goog.testing.MockControl&#39;);
<a name="line30"></a>goog.require(&#39;goog.testing.editor.FieldMock&#39;);
<a name="line31"></a>goog.require(&#39;goog.testing.editor.TestHelper&#39;);
<a name="line32"></a>goog.require(&#39;goog.testing.editor.dom&#39;);
<a name="line33"></a>goog.require(&#39;goog.testing.events&#39;);
<a name="line34"></a>goog.require(&#39;goog.testing.jsunit&#39;);
<a name="line35"></a>goog.require(&#39;goog.testing.mockmatchers&#39;);
<a name="line36"></a>goog.require(&#39;goog.ui.editor.AbstractDialog&#39;);
<a name="line37"></a>goog.require(&#39;goog.ui.editor.LinkDialog&#39;);
<a name="line38"></a>goog.require(&#39;goog.userAgent&#39;);
<a name="line39"></a>
<a name="line40"></a>var plugin;
<a name="line41"></a>var anchorElem;
<a name="line42"></a>var extraAnchors;
<a name="line43"></a>var isNew;
<a name="line44"></a>var testDiv;
<a name="line45"></a>
<a name="line46"></a>var mockCtrl;
<a name="line47"></a>var mockField;
<a name="line48"></a>var mockLink;
<a name="line49"></a>var mockAlert;
<a name="line50"></a>
<a name="line51"></a>var OLD_LINK_TEXT = &#39;old text&#39;;
<a name="line52"></a>var OLD_LINK_URL = &#39;http://old.url/&#39;;
<a name="line53"></a>var NEW_LINK_TEXT = &#39;My Link Text&#39;;
<a name="line54"></a>var NEW_LINK_URL = &#39;http://my.link/url/&#39;;
<a name="line55"></a>
<a name="line56"></a>var fieldElem;
<a name="line57"></a>var fieldObj;
<a name="line58"></a>var linkObj;
<a name="line59"></a>
<a name="line60"></a>function setUp() {
<a name="line61"></a>  testDiv = goog.dom.getDocument().getElementById(&#39;test&#39;);
<a name="line62"></a>  testDiv.innerHTML = &#39;Some preceeding text&#39;;
<a name="line63"></a>
<a name="line64"></a>  anchorElem = goog.dom.createElement(goog.dom.TagName.A);
<a name="line65"></a>  anchorElem.href = &#39;http://www.google.com/&#39;;
<a name="line66"></a>  anchorElem.innerHTML = &#39;anchor text&#39;;
<a name="line67"></a>  goog.dom.appendChild(testDiv, anchorElem);
<a name="line68"></a>  extraAnchors = [];
<a name="line69"></a>
<a name="line70"></a>  mockCtrl = new goog.testing.MockControl();
<a name="line71"></a>  mockField = new goog.testing.editor.FieldMock();
<a name="line72"></a>  mockCtrl.addMock(mockField);
<a name="line73"></a>  mockLink = mockCtrl.createLooseMock(goog.editor.Link);
<a name="line74"></a>  mockAlert = mockCtrl.createGlobalFunctionMock(&#39;alert&#39;);
<a name="line75"></a>
<a name="line76"></a>  isNew = false;
<a name="line77"></a>  mockLink.isNew().$anyTimes().$does(function() {
<a name="line78"></a>    return isNew;
<a name="line79"></a>  });
<a name="line80"></a>  mockLink.
<a name="line81"></a>      setTextAndUrl(goog.testing.mockmatchers.isString,
<a name="line82"></a>          goog.testing.mockmatchers.isString).
<a name="line83"></a>      $anyTimes().
<a name="line84"></a>      $does(function(text, url) {
<a name="line85"></a>        anchorElem.innerHTML = text;
<a name="line86"></a>        anchorElem.href = url;
<a name="line87"></a>      });
<a name="line88"></a>  mockLink.getAnchor().$anyTimes().$returns(anchorElem);
<a name="line89"></a>  mockLink.getExtraAnchors().$anyTimes().$returns(extraAnchors);
<a name="line90"></a>}
<a name="line91"></a>
<a name="line92"></a>function tearDown() {
<a name="line93"></a>  plugin.dispose();
<a name="line94"></a>  tearDownRealEditableField();
<a name="line95"></a>  testDiv.innerHTML = &#39;&#39;;
<a name="line96"></a>  mockCtrl.$tearDown();
<a name="line97"></a>}
<a name="line98"></a>
<a name="line99"></a>function setUpAnchor(text, href, opt_isNew, opt_target, opt_rel) {
<a name="line100"></a>  setUpGivenAnchor(anchorElem, text, href, opt_isNew, opt_target, opt_rel);
<a name="line101"></a>}
<a name="line102"></a>
<a name="line103"></a>function setUpGivenAnchor(
<a name="line104"></a>    anchor, text, href, opt_isNew, opt_target, opt_rel) {
<a name="line105"></a>  anchor.innerHTML = text;
<a name="line106"></a>  anchor.href = href;
<a name="line107"></a>  isNew = !!opt_isNew;
<a name="line108"></a>  if (opt_target) {
<a name="line109"></a>    anchor.target = opt_target;
<a name="line110"></a>  }
<a name="line111"></a>  if (opt_rel) {
<a name="line112"></a>    anchor.rel = opt_rel;
<a name="line113"></a>  }
<a name="line114"></a>}
<a name="line115"></a>
<a name="line116"></a>
<a name="line117"></a>/**
<a name="line118"></a> * Tests that the plugin&#39;s dialog is properly created.
<a name="line119"></a> */
<a name="line120"></a>function testCreateDialog() {
<a name="line121"></a>  // Note: this tests simply creating the dialog because that&#39;s the only
<a name="line122"></a>  // functionality added to this class. Opening or closing effects (editing
<a name="line123"></a>  // the actual link) is tested in linkdialog_test.html, but should be moved
<a name="line124"></a>  // here if that functionality gets refactored from the dialog to the plugin.
<a name="line125"></a>  mockCtrl.$replayAll();
<a name="line126"></a>
<a name="line127"></a>  plugin = new goog.editor.plugins.LinkDialogPlugin();
<a name="line128"></a>  plugin.registerFieldObject(mockField);
<a name="line129"></a>
<a name="line130"></a>  var dialog = plugin.createDialog(new goog.dom.DomHelper(), mockLink);
<a name="line131"></a>  assertTrue(&#39;Dialog should be of type goog.ui.editor.LinkDialog&#39;,
<a name="line132"></a>             dialog instanceof goog.ui.editor.LinkDialog);
<a name="line133"></a>
<a name="line134"></a>  mockCtrl.$verifyAll();
<a name="line135"></a>}
<a name="line136"></a>
<a name="line137"></a>
<a name="line138"></a>/**
<a name="line139"></a> * Tests that when the OK event fires the link is properly updated.
<a name="line140"></a> */
<a name="line141"></a>function testOk() {
<a name="line142"></a>  mockLink.placeCursorRightOf();
<a name="line143"></a>  mockField.dispatchSelectionChangeEvent();
<a name="line144"></a>  mockField.dispatchChange();
<a name="line145"></a>  mockField.focus();
<a name="line146"></a>  mockCtrl.$replayAll();
<a name="line147"></a>
<a name="line148"></a>  setUpAnchor(OLD_LINK_TEXT, OLD_LINK_URL);
<a name="line149"></a>  plugin = new goog.editor.plugins.LinkDialogPlugin();
<a name="line150"></a>  plugin.registerFieldObject(mockField);
<a name="line151"></a>  var dialog = plugin.createDialog(new goog.dom.DomHelper(), mockLink);
<a name="line152"></a>
<a name="line153"></a>  // Mock of execCommand + clicking OK without actually opening the dialog.
<a name="line154"></a>  plugin.currentLink_ = mockLink;
<a name="line155"></a>  dialog.dispatchEvent(new goog.ui.editor.LinkDialog.OkEvent(NEW_LINK_TEXT,
<a name="line156"></a>      NEW_LINK_URL));
<a name="line157"></a>
<a name="line158"></a>  assertEquals(&#39;Display text incorrect&#39;,
<a name="line159"></a>               NEW_LINK_TEXT,
<a name="line160"></a>               anchorElem.innerHTML);
<a name="line161"></a>  assertEquals(&#39;Anchor element href incorrect&#39;,
<a name="line162"></a>               NEW_LINK_URL,
<a name="line163"></a>               anchorElem.href);
<a name="line164"></a>
<a name="line165"></a>  mockCtrl.$verifyAll();
<a name="line166"></a>}
<a name="line167"></a>
<a name="line168"></a>
<a name="line169"></a>/**
<a name="line170"></a> * Tests that when the Cancel event fires the link is unchanged.
<a name="line171"></a> */
<a name="line172"></a>function testCancel() {
<a name="line173"></a>  mockCtrl.$replayAll();
<a name="line174"></a>
<a name="line175"></a>  setUpAnchor(OLD_LINK_TEXT, OLD_LINK_URL);
<a name="line176"></a>  plugin = new goog.editor.plugins.LinkDialogPlugin();
<a name="line177"></a>  plugin.registerFieldObject(mockField);
<a name="line178"></a>  var dialog = plugin.createDialog(new goog.dom.DomHelper(), mockLink);
<a name="line179"></a>
<a name="line180"></a>  // Mock of execCommand + cancel without actually opening the dialog.
<a name="line181"></a>  plugin.currentLink_ = mockLink;
<a name="line182"></a>  dialog.dispatchEvent(goog.ui.editor.AbstractDialog.EventType.CANCEL);
<a name="line183"></a>
<a name="line184"></a>  assertEquals(&#39;Display text should not be changed&#39;,
<a name="line185"></a>               OLD_LINK_TEXT,
<a name="line186"></a>               anchorElem.innerHTML);
<a name="line187"></a>  assertEquals(&#39;Anchor element href should not be changed&#39;,
<a name="line188"></a>               OLD_LINK_URL,
<a name="line189"></a>               anchorElem.href);
<a name="line190"></a>
<a name="line191"></a>  mockCtrl.$verifyAll();
<a name="line192"></a>}
<a name="line193"></a>
<a name="line194"></a>
<a name="line195"></a>/**
<a name="line196"></a> * Tests that when the Cancel event fires for a new link it gets removed.
<a name="line197"></a> */
<a name="line198"></a>function testCancelNew() {
<a name="line199"></a>  mockField.dispatchChange(); // Should be fired because link was removed.
<a name="line200"></a>  mockCtrl.$replayAll();
<a name="line201"></a>
<a name="line202"></a>  setUpAnchor(OLD_LINK_TEXT, OLD_LINK_URL, true);
<a name="line203"></a>  var prevSib = anchorElem.previousSibling;
<a name="line204"></a>  plugin = new goog.editor.plugins.LinkDialogPlugin();
<a name="line205"></a>  plugin.registerFieldObject(mockField);
<a name="line206"></a>  var dialog = plugin.createDialog(new goog.dom.DomHelper(), mockLink);
<a name="line207"></a>
<a name="line208"></a>  // Mock of execCommand + cancel without actually opening the dialog.
<a name="line209"></a>  plugin.currentLink_ = mockLink;
<a name="line210"></a>  dialog.dispatchEvent(goog.ui.editor.AbstractDialog.EventType.CANCEL);
<a name="line211"></a>
<a name="line212"></a>  assertNotEquals(&#39;Anchor element should be removed from document body&#39;,
<a name="line213"></a>                  testDiv,
<a name="line214"></a>                  anchorElem.parentNode);
<a name="line215"></a>  var newElem = prevSib.nextSibling;
<a name="line216"></a>  assertEquals(&#39;Link should be replaced by text node&#39;,
<a name="line217"></a>               goog.dom.NodeType.TEXT,
<a name="line218"></a>               newElem.nodeType);
<a name="line219"></a>  assertEquals(&#39;Original text should be left behind&#39;,
<a name="line220"></a>               OLD_LINK_TEXT,
<a name="line221"></a>               newElem.nodeValue);
<a name="line222"></a>
<a name="line223"></a>  mockCtrl.$verifyAll();
<a name="line224"></a>}
<a name="line225"></a>
<a name="line226"></a>
<a name="line227"></a>/**
<a name="line228"></a> * Tests that when the Cancel event fires for a new link it gets removed.
<a name="line229"></a> */
<a name="line230"></a>function testCancelNewMultiple() {
<a name="line231"></a>  mockField.dispatchChange(); // Should be fired because link was removed.
<a name="line232"></a>  mockCtrl.$replayAll();
<a name="line233"></a>
<a name="line234"></a>  var anchorElem1 = anchorElem;
<a name="line235"></a>  var parent1 = goog.dom.createDom(goog.dom.TagName.DIV, null,
<a name="line236"></a>      anchorElem1);
<a name="line237"></a>  goog.dom.appendChild(testDiv, parent1);
<a name="line238"></a>  setUpGivenAnchor(anchorElem1, OLD_LINK_TEXT + &#39;1&#39;, OLD_LINK_URL + &#39;1&#39;,
<a name="line239"></a>      true);
<a name="line240"></a>
<a name="line241"></a>  anchorElem2 = goog.dom.createDom(goog.dom.TagName.A);
<a name="line242"></a>  var parent2 = goog.dom.createDom(goog.dom.TagName.DIV, null,
<a name="line243"></a>      anchorElem2);
<a name="line244"></a>  goog.dom.appendChild(testDiv, parent2);
<a name="line245"></a>  setUpGivenAnchor(anchorElem2, OLD_LINK_TEXT + &#39;2&#39;, OLD_LINK_URL + &#39;2&#39;,
<a name="line246"></a>      true);
<a name="line247"></a>  extraAnchors.push(anchorElem2);
<a name="line248"></a>
<a name="line249"></a>  anchorElem3 = goog.dom.createDom(goog.dom.TagName.A);
<a name="line250"></a>  var parent3 = goog.dom.createDom(goog.dom.TagName.DIV, null,
<a name="line251"></a>      anchorElem3);
<a name="line252"></a>  goog.dom.appendChild(testDiv, parent3);
<a name="line253"></a>  setUpGivenAnchor(anchorElem3, OLD_LINK_TEXT + &#39;3&#39;, OLD_LINK_URL + &#39;3&#39;,
<a name="line254"></a>      true);
<a name="line255"></a>  extraAnchors.push(anchorElem3);
<a name="line256"></a>
<a name="line257"></a>  plugin = new goog.editor.plugins.LinkDialogPlugin();
<a name="line258"></a>  plugin.registerFieldObject(mockField);
<a name="line259"></a>  var dialog = plugin.createDialog(new goog.dom.DomHelper(), mockLink);
<a name="line260"></a>
<a name="line261"></a>  // Mock of execCommand + cancel without actually opening the dialog.
<a name="line262"></a>  plugin.currentLink_ = mockLink;
<a name="line263"></a>  dialog.dispatchEvent(goog.ui.editor.AbstractDialog.EventType.CANCEL);
<a name="line264"></a>
<a name="line265"></a>  assertNotEquals(&#39;Anchor 1 element should be removed from document body&#39;,
<a name="line266"></a>      parent1,
<a name="line267"></a>      anchorElem1.parentNode);
<a name="line268"></a>  assertNotEquals(&#39;Anchor 2 element should be removed from document body&#39;,
<a name="line269"></a>      parent2,
<a name="line270"></a>      anchorElem2.parentNode);
<a name="line271"></a>  assertNotEquals(&#39;Anchor 3 element should be removed from document body&#39;,
<a name="line272"></a>      parent3,
<a name="line273"></a>      anchorElem3.parentNode);
<a name="line274"></a>
<a name="line275"></a>  assertEquals(&#39;Link 1 should be replaced by text node&#39;,
<a name="line276"></a>      goog.dom.NodeType.TEXT,
<a name="line277"></a>      parent1.firstChild.nodeType);
<a name="line278"></a>  assertEquals(&#39;Link 2 should be replaced by text node&#39;,
<a name="line279"></a>      goog.dom.NodeType.TEXT,
<a name="line280"></a>      parent2.firstChild.nodeType);
<a name="line281"></a>  assertEquals(&#39;Link 3 should be replaced by text node&#39;,
<a name="line282"></a>      goog.dom.NodeType.TEXT,
<a name="line283"></a>      parent3.firstChild.nodeType);
<a name="line284"></a>
<a name="line285"></a>  assertEquals(&#39;Original text 1 should be left behind&#39;,
<a name="line286"></a>      OLD_LINK_TEXT + &#39;1&#39;,
<a name="line287"></a>      parent1.firstChild.nodeValue);
<a name="line288"></a>  assertEquals(&#39;Original text 2 should be left behind&#39;,
<a name="line289"></a>      OLD_LINK_TEXT + &#39;2&#39;,
<a name="line290"></a>      parent2.firstChild.nodeValue);
<a name="line291"></a>  assertEquals(&#39;Original text 3 should be left behind&#39;,
<a name="line292"></a>      OLD_LINK_TEXT + &#39;3&#39;,
<a name="line293"></a>      parent3.firstChild.nodeValue);
<a name="line294"></a>
<a name="line295"></a>  mockCtrl.$verifyAll();
<a name="line296"></a>}
<a name="line297"></a>
<a name="line298"></a>
<a name="line299"></a>/**
<a name="line300"></a> * Tests that when the Cancel event fires for a new link it gets removed.
<a name="line301"></a> */
<a name="line302"></a>function testOkNewMultiple() {
<a name="line303"></a>  mockLink.placeCursorRightOf();
<a name="line304"></a>  mockField.dispatchSelectionChangeEvent();
<a name="line305"></a>  mockField.dispatchChange();
<a name="line306"></a>  mockField.focus();
<a name="line307"></a>  mockCtrl.$replayAll();
<a name="line308"></a>
<a name="line309"></a>  var anchorElem1 = anchorElem;
<a name="line310"></a>  setUpGivenAnchor(anchorElem1, OLD_LINK_TEXT + &#39;1&#39;, OLD_LINK_URL + &#39;1&#39;,
<a name="line311"></a>      true);
<a name="line312"></a>
<a name="line313"></a>  anchorElem2 = goog.dom.createElement(goog.dom.TagName.A);
<a name="line314"></a>  goog.dom.appendChild(testDiv, anchorElem2);
<a name="line315"></a>  setUpGivenAnchor(anchorElem2, OLD_LINK_TEXT + &#39;2&#39;, OLD_LINK_URL + &#39;2&#39;,
<a name="line316"></a>      true);
<a name="line317"></a>  extraAnchors.push(anchorElem2);
<a name="line318"></a>
<a name="line319"></a>  anchorElem3 = goog.dom.createElement(goog.dom.TagName.A);
<a name="line320"></a>  goog.dom.appendChild(testDiv, anchorElem3);
<a name="line321"></a>  setUpGivenAnchor(anchorElem3, OLD_LINK_TEXT + &#39;3&#39;, OLD_LINK_URL + &#39;3&#39;,
<a name="line322"></a>      true);
<a name="line323"></a>  extraAnchors.push(anchorElem3);
<a name="line324"></a>
<a name="line325"></a>  var prevSib = anchorElem1.previousSibling;
<a name="line326"></a>  plugin = new goog.editor.plugins.LinkDialogPlugin();
<a name="line327"></a>  plugin.registerFieldObject(mockField);
<a name="line328"></a>  var dialog = plugin.createDialog(new goog.dom.DomHelper(), mockLink);
<a name="line329"></a>
<a name="line330"></a>  // Mock of execCommand + clicking OK without actually opening the dialog.
<a name="line331"></a>  plugin.currentLink_ = mockLink;
<a name="line332"></a>  dialog.dispatchEvent(new goog.ui.editor.LinkDialog.OkEvent(NEW_LINK_TEXT,
<a name="line333"></a>      NEW_LINK_URL));
<a name="line334"></a>
<a name="line335"></a>  assertEquals(&#39;Display text 1 must update&#39;, NEW_LINK_TEXT,
<a name="line336"></a>      anchorElem1.innerHTML);
<a name="line337"></a>  assertEquals(&#39;Display text 2 must not update&#39;, OLD_LINK_TEXT + &#39;2&#39;,
<a name="line338"></a>      anchorElem2.innerHTML);
<a name="line339"></a>  assertEquals(&#39;Display text 3 must not update&#39;, OLD_LINK_TEXT + &#39;3&#39;,
<a name="line340"></a>      anchorElem3.innerHTML);
<a name="line341"></a>
<a name="line342"></a>  assertEquals(&#39;Anchor element 1 href must update&#39;, NEW_LINK_URL,
<a name="line343"></a>      anchorElem1.href);
<a name="line344"></a>  assertEquals(&#39;Anchor element 2 href must update&#39;, NEW_LINK_URL,
<a name="line345"></a>      anchorElem2.href);
<a name="line346"></a>  assertEquals(&#39;Anchor element 3 href must update&#39;, NEW_LINK_URL,
<a name="line347"></a>      anchorElem3.href);
<a name="line348"></a>
<a name="line349"></a>  mockCtrl.$verifyAll();
<a name="line350"></a>}
<a name="line351"></a>
<a name="line352"></a>
<a name="line353"></a>/**
<a name="line354"></a> * Tests the anchor&#39;s target is correctly modified with the &quot;open in new
<a name="line355"></a> * window&quot; feature on.
<a name="line356"></a> */
<a name="line357"></a>function testOkOpenInNewWindow() {
<a name="line358"></a>  mockLink.placeCursorRightOf().$anyTimes();
<a name="line359"></a>  mockField.dispatchSelectionChangeEvent().$anyTimes();
<a name="line360"></a>  mockField.dispatchChange().$anyTimes();
<a name="line361"></a>  mockField.focus().$anyTimes();
<a name="line362"></a>  mockCtrl.$replayAll();
<a name="line363"></a>
<a name="line364"></a>  plugin = new goog.editor.plugins.LinkDialogPlugin();
<a name="line365"></a>  plugin.registerFieldObject(mockField);
<a name="line366"></a>  plugin.showOpenLinkInNewWindow(false);
<a name="line367"></a>  plugin.currentLink_ = mockLink;
<a name="line368"></a>
<a name="line369"></a>  // Edit a link that doesn&#39;t open in a new window and leave it as such.
<a name="line370"></a>  setUpAnchor(OLD_LINK_TEXT, OLD_LINK_URL);
<a name="line371"></a>  var dialog = plugin.createDialog(new goog.dom.DomHelper(), mockLink);
<a name="line372"></a>  dialog.dispatchEvent(new goog.ui.editor.LinkDialog.OkEvent(
<a name="line373"></a>      NEW_LINK_TEXT, NEW_LINK_URL, false, false));
<a name="line374"></a>  assertEquals(
<a name="line375"></a>      &#39;Target should not be set for link that doesn\&#39;t open in new window&#39;,
<a name="line376"></a>      &#39;&#39;, anchorElem.target);
<a name="line377"></a>  assertFalse(&#39;Checked state should stay false&#39;,
<a name="line378"></a>      plugin.getOpenLinkInNewWindowCheckedState());
<a name="line379"></a>
<a name="line380"></a>  // Edit a link that doesn&#39;t open in a new window and toggle it on.
<a name="line381"></a>  setUpAnchor(OLD_LINK_TEXT, OLD_LINK_URL);
<a name="line382"></a>  dialog = plugin.createDialog(new goog.dom.DomHelper(), mockLink);
<a name="line383"></a>  dialog.dispatchEvent(new goog.ui.editor.LinkDialog.OkEvent(
<a name="line384"></a>      NEW_LINK_TEXT, NEW_LINK_URL, true));
<a name="line385"></a>  assertEquals(
<a name="line386"></a>      &#39;Target should be set to _blank for link that opens in new window&#39;,
<a name="line387"></a>      &#39;_blank&#39;, anchorElem.target);
<a name="line388"></a>  assertTrue(&#39;Checked state should be true after toggling a link on&#39;,
<a name="line389"></a>      plugin.getOpenLinkInNewWindowCheckedState());
<a name="line390"></a>
<a name="line391"></a>  // Edit a link that doesn&#39;t open in a named window and don&#39;t touch it.
<a name="line392"></a>  setUpAnchor(OLD_LINK_TEXT, OLD_LINK_URL, false, &#39;named&#39;);
<a name="line393"></a>  dialog = plugin.createDialog(new goog.dom.DomHelper(), mockLink);
<a name="line394"></a>  dialog.dispatchEvent(new goog.ui.editor.LinkDialog.OkEvent(
<a name="line395"></a>      NEW_LINK_TEXT, NEW_LINK_URL, false));
<a name="line396"></a>  assertEquals(
<a name="line397"></a>      &#39;Target should keep its original value&#39;,
<a name="line398"></a>      &#39;named&#39;, anchorElem.target);
<a name="line399"></a>  assertFalse(&#39;Checked state should be false again&#39;,
<a name="line400"></a>      plugin.getOpenLinkInNewWindowCheckedState());
<a name="line401"></a>
<a name="line402"></a>  // Edit a link that opens in a new window and toggle it off.
<a name="line403"></a>  setUpAnchor(OLD_LINK_TEXT, OLD_LINK_URL, false, &#39;_blank&#39;);
<a name="line404"></a>  dialog = plugin.createDialog(new goog.dom.DomHelper(), mockLink);
<a name="line405"></a>  dialog.dispatchEvent(new goog.ui.editor.LinkDialog.OkEvent(
<a name="line406"></a>      NEW_LINK_TEXT, NEW_LINK_URL, false));
<a name="line407"></a>  assertEquals(
<a name="line408"></a>      &#39;Target should not be set for link that doesn\&#39;t open in new window&#39;,
<a name="line409"></a>      &#39;&#39;, anchorElem.target);
<a name="line410"></a>
<a name="line411"></a>  mockCtrl.$verifyAll();
<a name="line412"></a>}
<a name="line413"></a>
<a name="line414"></a>function testOkNoFollowEnabled() {
<a name="line415"></a>  verifyRelNoFollow(true, null, &#39;nofollow&#39;);
<a name="line416"></a>}
<a name="line417"></a>
<a name="line418"></a>function testOkNoFollowInUppercase() {
<a name="line419"></a>  verifyRelNoFollow(true, &#39;NOFOLLOW&#39;, &#39;NOFOLLOW&#39;);
<a name="line420"></a>}
<a name="line421"></a>
<a name="line422"></a>function testOkNoFollowEnabledHasMoreRelValues() {
<a name="line423"></a>  verifyRelNoFollow(true, &#39;author&#39;, &#39;author nofollow&#39;);
<a name="line424"></a>}
<a name="line425"></a>
<a name="line426"></a>function testOkNoFollowDisabled() {
<a name="line427"></a>  verifyRelNoFollow(false, null, &#39;&#39;);
<a name="line428"></a>}
<a name="line429"></a>
<a name="line430"></a>function testOkNoFollowDisabledHasMoreRelValues() {
<a name="line431"></a>  verifyRelNoFollow(false, &#39;author&#39;, &#39;author&#39;);
<a name="line432"></a>}
<a name="line433"></a>
<a name="line434"></a>function testOkNoFollowDisabledHasMoreRelValues() {
<a name="line435"></a>  verifyRelNoFollow(false, &#39;author nofollow&#39;, &#39;author &#39;);
<a name="line436"></a>}
<a name="line437"></a>
<a name="line438"></a>function testOkNoFollowInUppercaseWithMoreValues() {
<a name="line439"></a>  verifyRelNoFollow(true, &#39;NOFOLLOW author&#39;, &#39;NOFOLLOW author&#39;);
<a name="line440"></a>}
<a name="line441"></a>
<a name="line442"></a>function verifyRelNoFollow(noFollow, originalRel, expectedRel) {
<a name="line443"></a>  mockLink.placeCursorRightOf();
<a name="line444"></a>  mockField.dispatchSelectionChangeEvent();
<a name="line445"></a>  mockField.dispatchChange();
<a name="line446"></a>  mockField.focus();
<a name="line447"></a>  mockCtrl.$replayAll();
<a name="line448"></a>
<a name="line449"></a>  plugin = new goog.editor.plugins.LinkDialogPlugin();
<a name="line450"></a>  plugin.registerFieldObject(mockField);
<a name="line451"></a>  plugin.showRelNoFollow();
<a name="line452"></a>  plugin.currentLink_ = mockLink;
<a name="line453"></a>
<a name="line454"></a>  setUpAnchor(OLD_LINK_TEXT, OLD_LINK_URL, true, null, originalRel);
<a name="line455"></a>  var dialog = plugin.createDialog(new goog.dom.DomHelper(), mockLink);
<a name="line456"></a>  dialog.dispatchEvent(new goog.ui.editor.LinkDialog.OkEvent(
<a name="line457"></a>      NEW_LINK_TEXT, NEW_LINK_URL, false, noFollow));
<a name="line458"></a>  assertEquals(expectedRel, anchorElem.rel);
<a name="line459"></a>
<a name="line460"></a>  mockCtrl.$verifyAll();
<a name="line461"></a>}
<a name="line462"></a>
<a name="line463"></a>
<a name="line464"></a>/**
<a name="line465"></a> * Tests that the selection is cleared when the dialog opens and is
<a name="line466"></a> * correctly restored after cancel is clicked.
<a name="line467"></a> */
<a name="line468"></a>function testRestoreSelectionOnOk() {
<a name="line469"></a>  setUpAnchor(&#39;12345&#39;, &#39;/&#39;);
<a name="line470"></a>  setUpRealEditableField();
<a name="line471"></a>
<a name="line472"></a>  var elem = fieldObj.getElement();
<a name="line473"></a>  var helper = new goog.testing.editor.TestHelper(elem);
<a name="line474"></a>  helper.select(&#39;12345&#39;, 1, &#39;12345&#39;, 4); // Selects &#39;234&#39;.
<a name="line475"></a>
<a name="line476"></a>  assertEquals(&#39;Incorrect text selected before dialog is opened&#39;,
<a name="line477"></a>               &#39;234&#39;,
<a name="line478"></a>               fieldObj.getRange().getText());
<a name="line479"></a>  plugin.execCommand(goog.editor.Command.MODAL_LINK_EDITOR, linkObj);
<a name="line480"></a>  if (!goog.userAgent.IE &amp;&amp; !goog.userAgent.OPERA) {
<a name="line481"></a>    // IE returns some bogus range when field doesn&#39;t have selection.
<a name="line482"></a>    // You can&#39;t remove the selection from a whitebox field in Opera.
<a name="line483"></a>    assertNull(&#39;There should be no selection while dialog is open&#39;,
<a name="line484"></a>               fieldObj.getRange());
<a name="line485"></a>  }
<a name="line486"></a>  goog.testing.events.fireClickSequence(
<a name="line487"></a>      plugin.dialog_.getOkButtonElement());
<a name="line488"></a>  assertEquals(&#39;No text should be selected after clicking ok&#39;,
<a name="line489"></a>               &#39;&#39;,
<a name="line490"></a>               fieldObj.getRange().getText());
<a name="line491"></a>
<a name="line492"></a>  // Test that the caret is placed at the end of the link text.
<a name="line493"></a>  goog.testing.editor.dom.assertRangeBetweenText(
<a name="line494"></a>      // If the browser gets stuck in links, an nbsp was added after the link
<a name="line495"></a>      // to avoid that, otherwise we just look for the 5.
<a name="line496"></a>      goog.editor.BrowserFeature.GETS_STUCK_IN_LINKS ?
<a name="line497"></a>          goog.string.Unicode.NBSP : &#39;5&#39;,
<a name="line498"></a>      &#39;&#39;,
<a name="line499"></a>      fieldObj.getRange());
<a name="line500"></a>
<a name="line501"></a>  // NOTE(user): The functionality to avoid getting stuck in links is
<a name="line502"></a>  // tested in editablelink_test.html::testPlaceCursorRightOf().
<a name="line503"></a>}
<a name="line504"></a>
<a name="line505"></a>
<a name="line506"></a>/**
<a name="line507"></a> * Tests that the selection is cleared when the dialog opens and is
<a name="line508"></a> * correctly restored after cancel is clicked.
<a name="line509"></a> * @param {boolean=} opt_isNew Whether to test behavior when creating a new
<a name="line510"></a> *     link (cancelling will flatten it).
<a name="line511"></a> */
<a name="line512"></a>function testRestoreSelectionOnCancel(opt_isNew) {
<a name="line513"></a>  setUpAnchor(&#39;12345&#39;, &#39;/&#39;, opt_isNew);
<a name="line514"></a>  setUpRealEditableField();
<a name="line515"></a>
<a name="line516"></a>  var elem = fieldObj.getElement();
<a name="line517"></a>  var helper = new goog.testing.editor.TestHelper(elem);
<a name="line518"></a>  helper.select(&#39;12345&#39;, 1, &#39;12345&#39;, 4); // Selects &#39;234&#39;.
<a name="line519"></a>
<a name="line520"></a>  assertEquals(&#39;Incorrect text selected before dialog is opened&#39;,
<a name="line521"></a>               &#39;234&#39;,
<a name="line522"></a>               fieldObj.getRange().getText());
<a name="line523"></a>  plugin.execCommand(goog.editor.Command.MODAL_LINK_EDITOR, linkObj);
<a name="line524"></a>  if (!goog.userAgent.IE &amp;&amp; !goog.userAgent.OPERA) {
<a name="line525"></a>    // IE returns some bogus range when field doesn&#39;t have selection.
<a name="line526"></a>    // You can&#39;t remove the selection from a whitebox field in Opera.
<a name="line527"></a>    assertNull(&#39;There should be no selection while dialog is open&#39;,
<a name="line528"></a>               fieldObj.getRange());
<a name="line529"></a>  }
<a name="line530"></a>  goog.testing.events.fireClickSequence(
<a name="line531"></a>      plugin.dialog_.getCancelButtonElement());
<a name="line532"></a>  assertEquals(&#39;Incorrect text selected after clicking cancel&#39;,
<a name="line533"></a>               &#39;234&#39;,
<a name="line534"></a>               fieldObj.getRange().getText());
<a name="line535"></a>}
<a name="line536"></a>
<a name="line537"></a>
<a name="line538"></a>/**
<a name="line539"></a> * Tests that the selection is cleared when the dialog opens and is
<a name="line540"></a> * correctly restored after cancel is clicked and the new link is removed.
<a name="line541"></a> */
<a name="line542"></a>function testRestoreSelectionOnCancelNew() {
<a name="line543"></a>  testRestoreSelectionOnCancel(true);
<a name="line544"></a>}
<a name="line545"></a>
<a name="line546"></a>
<a name="line547"></a>/**
<a name="line548"></a> * Tests that the BeforeTestLink event is suppressed for invalid url schemes.
<a name="line549"></a> */
<a name="line550"></a>function testTestLinkDisabledForInvalidScheme() {
<a name="line551"></a>  mockAlert(goog.testing.mockmatchers.isString);
<a name="line552"></a>  mockCtrl.$replayAll();
<a name="line553"></a>
<a name="line554"></a>  var invalidUrl = &#39;javascript:document.write(\&#39;hello\&#39;);&#39;;
<a name="line555"></a>
<a name="line556"></a>  plugin = new goog.editor.plugins.LinkDialogPlugin();
<a name="line557"></a>  var dialog = plugin.createDialog(new goog.dom.DomHelper(), mockLink);
<a name="line558"></a>
<a name="line559"></a>  // Mock of execCommand + clicking test without actually opening the dialog.
<a name="line560"></a>  var dispatched = dialog.dispatchEvent(
<a name="line561"></a>      new goog.ui.editor.LinkDialog.BeforeTestLinkEvent(invalidUrl));
<a name="line562"></a>
<a name="line563"></a>  assertFalse(dispatched);
<a name="line564"></a>  mockCtrl.$verifyAll();
<a name="line565"></a>}
<a name="line566"></a>
<a name="line567"></a>function testIsSafeSchemeToOpen() {
<a name="line568"></a>  plugin = new goog.editor.plugins.LinkDialogPlugin();
<a name="line569"></a>  // Urls with no scheme at all are ok too since &#39;http://&#39; will be prepended.
<a name="line570"></a>  var good = [
<a name="line571"></a>    &#39;http://google.com&#39;, &#39;http://google.com/&#39;, &#39;https://google.com&#39;,
<a name="line572"></a>    &#39;null@google.com&#39;, &#39;http://www.google.com&#39;, &#39;http://site.com&#39;,
<a name="line573"></a>    &#39;google.com&#39;, &#39;google&#39;, &#39;http://google&#39;, &#39;HTTP://GOOGLE.COM&#39;,
<a name="line574"></a>    &#39;HtTp://www.google.com&#39;
<a name="line575"></a>  ];
<a name="line576"></a>
<a name="line577"></a>  var bad = [
<a name="line578"></a>    &#39;javascript:google.com&#39;, &#39;httpp://google.com&#39;, &#39;data:foo&#39;,
<a name="line579"></a>    &#39;javascript:alert(\&#39;hi\&#39;);&#39;, &#39;abc:def&#39;
<a name="line580"></a>  ];
<a name="line581"></a>
<a name="line582"></a>  for (var i = 0; i &lt; good.length; i++) {
<a name="line583"></a>    assertTrue(good[i] + &#39; should have a safe scheme&#39;,
<a name="line584"></a>        plugin.isSafeSchemeToOpen_(good[i]));
<a name="line585"></a>  }
<a name="line586"></a>
<a name="line587"></a>  for (i = 0; i &lt; bad.length; i++) {
<a name="line588"></a>    assertFalse(bad[i] + &#39; should have an unsafe scheme&#39;,
<a name="line589"></a>        plugin.isSafeSchemeToOpen_(bad[i]));
<a name="line590"></a>  }
<a name="line591"></a>}
<a name="line592"></a>
<a name="line593"></a>function testShouldOpenWithWhitelist() {
<a name="line594"></a>  plugin.setSafeToOpenSchemes([&#39;abc&#39;]);
<a name="line595"></a>
<a name="line596"></a>  assertTrue(&#39;Scheme should be safe&#39;,
<a name="line597"></a>      plugin.shouldOpenUrl(&#39;abc://google.com&#39;));
<a name="line598"></a>  assertFalse(&#39;Scheme should be unsafe&#39;,
<a name="line599"></a>              plugin.shouldOpenUrl(&#39;http://google.com&#39;));
<a name="line600"></a>
<a name="line601"></a>  plugin.setBlockOpeningUnsafeSchemes(false);
<a name="line602"></a>  assertTrue(&#39;Non-whitelisted should now be safe after disabling blocking&#39;,
<a name="line603"></a>      plugin.shouldOpenUrl(&#39;http://google.com&#39;));
<a name="line604"></a>}
<a name="line605"></a>
<a name="line606"></a>
<a name="line607"></a>/**
<a name="line608"></a> * Regression test for http://b/issue?id=1607766 . Without the fix, this
<a name="line609"></a> * should give an Invalid Argument error in IE, because the editable field
<a name="line610"></a> * caches a selection util that has a reference to the node of the link text
<a name="line611"></a> * before it is edited (which gets replaced by a new node for the new text
<a name="line612"></a> * after editing).
<a name="line613"></a> */
<a name="line614"></a>function testBug1607766() {
<a name="line615"></a>  setUpAnchor(&#39;abc&#39;, &#39;def&#39;);
<a name="line616"></a>  setUpRealEditableField();
<a name="line617"></a>
<a name="line618"></a>  var elem = fieldObj.getElement();
<a name="line619"></a>  var helper = new goog.testing.editor.TestHelper(elem);
<a name="line620"></a>  helper.select(&#39;abc&#39;, 1, &#39;abc&#39;, 2); // Selects &#39;b&#39;.
<a name="line621"></a>  // Dispatching a selection event causes the field to cache a selection
<a name="line622"></a>  // util, which is the root of the bug.
<a name="line623"></a>  plugin.fieldObject.dispatchSelectionChangeEvent();
<a name="line624"></a>
<a name="line625"></a>  plugin.execCommand(goog.editor.Command.MODAL_LINK_EDITOR, linkObj);
<a name="line626"></a>  goog.dom.getElement(
<a name="line627"></a>      goog.ui.editor.LinkDialog.Id_.TEXT_TO_DISPLAY).value = &#39;Abc&#39;;
<a name="line628"></a>  goog.testing.events.fireClickSequence(plugin.dialog_.getOkButtonElement());
<a name="line629"></a>
<a name="line630"></a>  // In IE the unit test somehow doesn&#39;t cause a browser focus event, so we
<a name="line631"></a>  // need to manually invoke this, which is where the bug happens.
<a name="line632"></a>  plugin.fieldObject.dispatchFocus_();
<a name="line633"></a>}
<a name="line634"></a>
<a name="line635"></a>
<a name="line636"></a>/**
<a name="line637"></a> * Regression test for http://b/issue?id=2215546 .
<a name="line638"></a> */
<a name="line639"></a>function testBug2215546() {
<a name="line640"></a>  setUpRealEditableField();
<a name="line641"></a>
<a name="line642"></a>  var elem = fieldObj.getElement();
<a name="line643"></a>  fieldObj.setHtml(false, &#39;&lt;div&gt;&lt;a href=&quot;/&quot;&gt;&lt;/a&gt;&lt;/div&gt;&#39;);
<a name="line644"></a>  anchorElem = elem.firstChild.firstChild;
<a name="line645"></a>  linkObj = new goog.editor.Link(anchorElem, true);
<a name="line646"></a>
<a name="line647"></a>  var helper = new goog.testing.editor.TestHelper(elem);
<a name="line648"></a>  // Select &quot;&lt;/a&gt;&quot; in a way, simulating what IE does if you hit enter twice,
<a name="line649"></a>  // arrow up into the blank line and open the link dialog.
<a name="line650"></a>  helper.select(anchorElem, 0, elem.firstChild, 1);
<a name="line651"></a>
<a name="line652"></a>  plugin.execCommand(goog.editor.Command.MODAL_LINK_EDITOR, linkObj);
<a name="line653"></a>  goog.dom.getElement(
<a name="line654"></a>      goog.ui.editor.LinkDialog.Id_.TEXT_TO_DISPLAY).value = &#39;foo&#39;;
<a name="line655"></a>  goog.dom.getElement(
<a name="line656"></a>      goog.ui.editor.LinkDialog.Id_.ON_WEB_INPUT).value = &#39;foo&#39;;
<a name="line657"></a>  var okButton = plugin.dialog_.getOkButtonElement();
<a name="line658"></a>  okButton.disabled = false;
<a name="line659"></a>  goog.testing.events.fireClickSequence(okButton);
<a name="line660"></a>
<a name="line661"></a>  assertEquals(&#39;Link text should have been inserted&#39;,
<a name="line662"></a>               &#39;foo&#39;, anchorElem.innerHTML);
<a name="line663"></a>}
<a name="line664"></a>
<a name="line665"></a>
<a name="line666"></a>/**
<a name="line667"></a> * Test that link insertion doesn&#39;t scroll the field to the top
<a name="line668"></a> * after clicking Cancel or OK.
<a name="line669"></a> */
<a name="line670"></a>function testBug7279077ScrollOnFocus() {
<a name="line671"></a>  if (goog.userAgent.IE) {
<a name="line672"></a>    return;  // TODO(user): take this out once b/7279077 fixed for IE too.
<a name="line673"></a>  }
<a name="line674"></a>  setUpAnchor(&#39;12345&#39;, &#39;/&#39;);
<a name="line675"></a>  setUpRealEditableField();
<a name="line676"></a>
<a name="line677"></a>  // Make the field scrollable and kinda small.
<a name="line678"></a>  var elem = fieldObj.getElement();
<a name="line679"></a>  elem.style.overflow = &#39;auto&#39;;
<a name="line680"></a>  elem.style.height = &#39;40px&#39;;
<a name="line681"></a>  elem.style.width = &#39;200px&#39;;
<a name="line682"></a>  elem.style.contenteditable = &#39;true&#39;;
<a name="line683"></a>
<a name="line684"></a>  // Add a bunch of text before the anchor tag.
<a name="line685"></a>  var longTextElem = document.createElement(&#39;span&#39;);
<a name="line686"></a>  longTextElem.innerHTML = goog.string.repeat(&#39;All work and no play.&lt;p&gt;&#39;, 20);
<a name="line687"></a>  elem.insertBefore(longTextElem, elem.firstChild);
<a name="line688"></a>
<a name="line689"></a>  var helper = new goog.testing.editor.TestHelper(elem);
<a name="line690"></a>  helper.select(&#39;12345&#39;, 1, &#39;12345&#39;, 4); // Selects &#39;234&#39;.
<a name="line691"></a>
<a name="line692"></a>  // Scroll down.
<a name="line693"></a>  elem.scrollTop = 60;
<a name="line694"></a>
<a name="line695"></a>  // Bring up the link insertion dialog, then cancel.
<a name="line696"></a>  plugin.execCommand(goog.editor.Command.MODAL_LINK_EDITOR, linkObj);
<a name="line697"></a>  goog.dom.getElement(
<a name="line698"></a>      goog.ui.editor.LinkDialog.Id_.TEXT_TO_DISPLAY).value = &#39;foo&#39;;
<a name="line699"></a>  goog.dom.getElement(
<a name="line700"></a>      goog.ui.editor.LinkDialog.Id_.ON_WEB_INPUT).value = &#39;foo&#39;;
<a name="line701"></a>  var cancelButton = plugin.dialog_.getCancelButtonElement();
<a name="line702"></a>  goog.testing.events.fireClickSequence(cancelButton);
<a name="line703"></a>
<a name="line704"></a>  assertEquals(&#39;Field should not have scrolled after cancel&#39;,
<a name="line705"></a>      60, elem.scrollTop);
<a name="line706"></a>
<a name="line707"></a>  // Now let&#39;s try it with clicking the OK button.
<a name="line708"></a>  plugin.execCommand(goog.editor.Command.MODAL_LINK_EDITOR, linkObj);
<a name="line709"></a>  goog.dom.getElement(
<a name="line710"></a>      goog.ui.editor.LinkDialog.Id_.TEXT_TO_DISPLAY).value = &#39;foo&#39;;
<a name="line711"></a>  goog.dom.getElement(
<a name="line712"></a>      goog.ui.editor.LinkDialog.Id_.ON_WEB_INPUT).value = &#39;foo&#39;;
<a name="line713"></a>  var okButton = plugin.dialog_.getOkButtonElement();
<a name="line714"></a>  goog.testing.events.fireClickSequence(okButton);
<a name="line715"></a>
<a name="line716"></a>  assertEquals(&#39;Field should not have scrolled after OK&#39;,
<a name="line717"></a>      60, elem.scrollTop);
<a name="line718"></a>}
<a name="line719"></a>
<a name="line720"></a>
<a name="line721"></a>/**
<a name="line722"></a> * Setup a real editable field (instead of a mock) and register the plugin to
<a name="line723"></a> * it.
<a name="line724"></a> */
<a name="line725"></a>function setUpRealEditableField() {
<a name="line726"></a>  fieldElem = document.createElement(&#39;div&#39;);
<a name="line727"></a>  fieldElem.id = &#39;myField&#39;;
<a name="line728"></a>  document.body.appendChild(fieldElem);
<a name="line729"></a>  fieldElem.appendChild(anchorElem);
<a name="line730"></a>  fieldObj = new goog.editor.Field(&#39;myField&#39;, document);
<a name="line731"></a>  fieldObj.makeEditable();
<a name="line732"></a>  linkObj = new goog.editor.Link(fieldObj.getElement().firstChild, isNew);
<a name="line733"></a>  // Register the plugin to that field.
<a name="line734"></a>  plugin = new goog.editor.plugins.LinkDialogPlugin();
<a name="line735"></a>  fieldObj.registerPlugin(plugin);
<a name="line736"></a>}
<a name="line737"></a>
<a name="line738"></a>
<a name="line739"></a>/**
<a name="line740"></a> * Tear down the real editable field.
<a name="line741"></a> */
<a name="line742"></a>function tearDownRealEditableField() {
<a name="line743"></a>  if (fieldObj) {
<a name="line744"></a>    fieldObj.makeUneditable();
<a name="line745"></a>    fieldObj.dispose();
<a name="line746"></a>    fieldObj = null;
<a name="line747"></a>  }
<a name="line748"></a>  goog.dom.removeNode(fieldElem);
<a name="line749"></a>}
</pre>


</body>
</html>
